<?php

$conn = new mysqli("localhost", "root", "root");

function createdb()
{
	global $conn;
	$conn->query("CREATE DATABASE tmp123");
}

function createtable()
{
	global $conn;
	$conn->query("USE tmp123");
	$conn->query("CREATE TABLE usertest (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,`username` CHAR(32) NOT NULL,`passwd` CHAR(32) NOT NULL,`email` CHAR(100) NOT NULL,`hash` CHAR(32) NOT NULL,PRIMARY KEY (`id`)  )");
}

function insertrows()
{
	global $conn;
	for($i=1; $i < 90001; $i++)
	{
		$strpass = mt_rand(111,999);
		$hash = md5("example".$i.$strpass."example".$i."@example.com");
		$conn->query("INSERT INTO usertest (`id`,`username`,`passwd`,`email`,`hash`) VALUES ( NULL,'example$i','$strpass','example$i@example.com','$hash')");
	}
}

function selectrows()
{
	global $conn;
	$rows = $conn->query("SELECT * FROM usertest");
	while($row = $rows->fetch_assoc())
	{
		$hashnew = md5($row["username"].$row["passwd"].$row["email"]);
		if ($hashnew != $row["hash"])
			echo "Something went wrong!";
	}
}

function deleterows()
{
	global $conn;
	$conn->query("DELETE FROM usertest");
}

function deletetable()
{
	global $conn;
	$conn->query("DROP TABLE usertest");
}

function deletedb()
{
	global $conn;
	$conn->query("DROP DATABASE tmp123");
	$conn->close();
}

createdb();
createtable();
insertrows();
selectrows();
deleterows();
deletetable();
deletedb();

?>